// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   FlowCaution.java

package include.alarm;

import include.nseer_db.nseer_db;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FlowCaution
{

	private ResultSet rs;
	private ResultSet rs1;
	private String sql1;
	private String date;
	private String dbase;
	private String table1;
	private String table2;
	private String table3;
	private String field1;
	private String field2;
	private String field3;
	private String idgroup[];
	private String alarmgroup[];

	public FlowCaution()
	{
		rs = null;
		rs1 = null;
		sql1 = "";
		date = "";
		idgroup = new String[0xf4240];
		alarmgroup = new String[0xf4240];
	}

	public void flow(String dbase, String table1, String table2, String table3, String field1, String field2, String field3)
	{
		this.dbase = dbase;
		this.table1 = table1;
		this.table2 = table2;
		this.table3 = table3;
		this.field1 = field1;
		this.field2 = field2;
		this.field3 = field3;
		nseer_db db = new nseer_db(dbase);
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		Date now = new Date();
		try
		{
			String sql3 = (new StringBuilder("delete from ")).append(table1).toString();
			db.executeUpdate(sql3);
			String sql = (new StringBuilder("select * from ")).append(table2).append(" where tag='1'").toString();
			rs = db.executeQuery(sql);
			int i;
			for (i = 0; rs.next(); i++)
			{
				idgroup[i] = rs.getString(field1);
				alarmgroup[i] = rs.getString(field2);
			}

			for (int j = 0; j < i; j++)
			{
				sql1 = (new StringBuilder("select * from ")).append(table3).append(" where ").append(field1).append("='").append(idgroup[j]).append("' order by ").append(field3).append(" desc").toString();
				rs1 = db.executeQuery(sql1);
				if (rs1.next())
					date = rs1.getString(field3);
				else
					date = "";
				if (!date.equals(""))
				{
					Date date1 = formatter.parse(date);
					long Time = date1.getTime() / 1000L + (long)(0x15180 * Integer.parseInt(alarmgroup[j]));
					date1.setTime(Time * 1000L);
					if (date1.getTime() - now.getTime() < 0L)
					{
						long days = (long)((double)((now.getTime() - date1.getTime()) / 0x5265c00L) + 0.5D);
						String sql2 = (new StringBuilder("insert into ")).append(table1).append("(").append(field1).append(",lasttime,").append(field2).append(",days) values('").append(idgroup[j]).append("','").append(date).append("','").append(alarmgroup[j]).append("','").append(days).append("')").toString();
						db.executeUpdate(sql2);
					}
				}
			}

			db.close();
		}
		catch (Exception exception) { }
	}
}
